package socket.ip;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * @author 周宇
 * @create 2020-08-18 17:08
 */
public class URLDemo {
    public static void main(String[] args) {
        try {
            URL url = new URL("http://localhost:8080/helloworld/index.jsp?username=kuangshen&password=123");

            System.out.println(url.getProtocol());//获取URL协议名 http
            System.out.println(url.getHost());//获取URL主机名 localhost
            System.out.println(url.getPort());//获得URL端口号 8080
            System.out.println(url.getFile());//获得URL的文件名 /helloworld/index.jsp?username=kuangshen&password=123
            System.out.println(url.getPath());//获得URL文件路径 /helloworld/index.jsp
            System.out.println(url.getQuery());//获得URL的查询名 username=kuangshen&password=123
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }
}
